package com.sig.util;

import com.google.common.collect.*;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

import java.lang.reflect.Array;
import java.util.*;

/**
 * 字符串处理工具
 *
 * @author sig
 * @since 2019/1/29
 */
public final class SplitUtil {

    private SplitUtil() {
    }

    /**
     * 移除小数浮点位数
     *
     * @param value
     * @return
     */
    public static String removeFloat(final String value) {
        if (StringUtils.isBlank(value))
            return value;
        return value.replaceAll("\\.0", "");
    }

    /**
     * 把字符串转换成具体类型对象
     *
     * @param value
     * @param clazz
     * @param <T>
     * @return
     */
    @SuppressWarnings("unchecked")
    private static <T> T convert2ConcreteType(final String value, final Class<T> clazz) {
        if (String.class.equals(clazz)) {
            return (T) value;
        } else if (Integer.class.equals(clazz)) {
            return (T) Integer.valueOf(removeFloat(value));
        } else if (Long.class.equals(clazz)) {
            return (T) Long.valueOf(removeFloat(value));
        } else if (Float.class.equals(clazz)) {
            return (T) Float.valueOf(value);
        } else if (Double.class.equals(clazz)) {
            return (T) Double.valueOf(value);
        } else if (Byte.class.equals(clazz)) {
            return (T) Byte.valueOf(removeFloat(value));
        } else if (Short.class.equals(clazz)) {
            return (T) Short.valueOf(removeFloat(value));
        } else if (Boolean.class.equals(clazz)) {
            return (T) Boolean.valueOf(value);
        } else {
            throw new IllegalArgumentException("can't find concrete type：" + clazz.getName());
        }
    }

    /**
     * 把字符串切割成T[]
     *
     * @param value 要切割的字符串，如"1=1,2=2,3=3"
     * @param split 分隔符
     * @param clazz 类类型
     * @param <T>
     * @return
     */
    @SuppressWarnings("unchecked")
    public static <T> T[] split2Array(String value, final String split, final Class<T> clazz) {
        if (StringUtils.isBlank(value))
            return null;
        value = StringUtils.remove(value, ' ');
        final String[] array = value.split(split);
        final int length = array.length;
        final T[] newArray = (T[]) Array.newInstance(clazz, length);
        for (int index = 0; index < length; index++)
            newArray[index] = convert2ConcreteType(array[index], clazz);
        return newArray;
    }

    /**
     * 把字符串切割成List<T>
     *
     * @param value 要切割的字符串，如"1=1,2=2,3=3"
     * @param split 分隔符
     * @param clazz 类类型
     * @param <T>
     * @return
     */
    public static <T> List<T> split2List(String value, final String split, final Class<T> clazz) {
        return split2List(value, split, clazz, false);
    }

    /**
     * 把字符串切割成List<T>
     *
     * @param value     要切割的字符串，如"1=1,2=2,3=3"
     * @param split     分隔符
     * @param clazz     类类型
     * @param immutable 集合是否不可变
     * @param <T>
     * @return
     */
    public static <T> List<T> split2List(String value, final String split, final Class<T> clazz, final boolean immutable) {
        if (StringUtils.isBlank(value))
            return null;
        value = StringUtils.remove(value, ' ');
        final String[] array = value.split(split);
        final int length = array.length;
        final List<T> list = Lists.newArrayListWithExpectedSize(length);
        for (int index = 0; index < length; index++)
            list.add(convert2ConcreteType(array[index], clazz));
        return immutable ? ImmutableList.copyOf(list) : list;
    }

    /**
     * 把字符串切割成List<T[]>
     *
     * @param value  要切割的字符串，如"1=1,2=2,3=3"
     * @param split1 第一层分隔符
     * @param split2 第二层分隔符
     * @param clazz  类类型
     * @param <T>
     * @return
     */
    public static <T> List<T[]> split2ArrayList(String value, final String split1, final String split2, final Class<T> clazz) {
        return split2ArrayList(value, split1, split2, clazz, false);
    }

    /**
     * 把字符串切割成List<T[]>
     *
     * @param value     要切割的字符串，如"1=1,2=2,3=3"
     * @param split1    第一层分隔符
     * @param split2    第二层分隔符
     * @param clazz     类类型
     * @param immutable 集合是否不可变
     * @param <T>
     * @return
     */
    public static <T> List<T[]> split2ArrayList(String value, final String split1, final String split2, final Class<T> clazz, final boolean immutable) {
        if (StringUtils.isBlank(value))
            return null;
        value = StringUtils.remove(value, ' ');
        final String[] array = value.split(split1);
        final int length = array.length;
        final List<T[]> list = Lists.newArrayListWithExpectedSize(length);
        for (int index = 0; index < length; index++)
            list.add(split2Array(array[index], split2, clazz));
        return immutable ? ImmutableList.copyOf(list) : list;
    }

    /**
     * 把字符串切割成Set<T>
     *
     * @param value 要切割的字符串，如"1=1,2=2,3=3"
     * @param split 分隔符
     * @param clazz 类类型
     * @param <T>
     * @return
     */
    public static <T> Set<T> split2Set(String value, final String split, final Class<T> clazz) {
        return split2Set(value, split, clazz, false);
    }

    /**
     * 把字符串切割成Set<T>
     *
     * @param value     要切割的字符串，如"1=1,2=2,3=3"
     * @param split     分隔符
     * @param clazz     类类型
     * @param immutable 集合是否不可变
     * @param <T>
     * @return
     */
    public static <T> Set<T> split2Set(String value, final String split, final Class<T> clazz, final boolean immutable) {
        if (StringUtils.isBlank(value))
            return null;
        value = StringUtils.remove(value, ' ');
        final String[] array = value.split(split);
        final int length = array.length;
        final Set<T> set = Sets.newHashSetWithExpectedSize(length);
        for (int index = 0; index < length; index++)
            set.add(convert2ConcreteType(array[index], clazz));
        return immutable ? ImmutableSet.copyOf(set) : set;
    }

    /**
     * 把字符串切割成Map<K, V>
     *
     * @param value  要切割的字符串，如"1=1,2=2,3=3"
     * @param split1 第一层分隔符
     * @param split2 第二层分隔符
     * @param kClazz k类类型
     * @param vClazz v类类型
     * @param <K>
     * @param <V>
     * @return
     */
    public static <K, V> Map<K, V> split2Map(String value, final String split1, final String split2, final Class<K> kClazz, final Class<V> vClazz) {
        return split2Map(value, split1, split2, kClazz, vClazz, false);
    }

    /**
     * 把字符串切割成Map<K, V>
     *
     * @param value     要切割的字符串，如"1=1,2=2,3=3"
     * @param split1    第一层分隔符
     * @param split2    第二层分隔符
     * @param kClazz    k类类型
     * @param vClazz    v类类型
     * @param immutable 集合是否不可变
     * @param <K>
     * @param <V>
     * @return
     */
    public static <K, V> Map<K, V> split2Map(String value, final String split1, final String split2, final Class<K> kClazz, final Class<V> vClazz, final boolean immutable) {
        if (StringUtils.isBlank(value))
            return null;
        value = StringUtils.remove(value, ' ');
        final String[] array = value.split(split1);
        final int length = array.length;
        final Map<K, V> map = Maps.newLinkedHashMapWithExpectedSize(length);
        for (int index = 0; index < length; index++) {
            final String[] secondArray = array[index].split(split2);
            final K k = convert2ConcreteType(secondArray[0], kClazz);
            final V v = convert2ConcreteType(secondArray[1], vClazz);
            map.put(k, v);
        }
        return immutable ? ImmutableMap.copyOf(map) : map;
    }

    /**
     * 把字符串切割成int[]
     *
     * @param value 要切割的字符串，如"1,2,3"
     * @param split 分隔符
     * @return
     */
    public static int[] split2IntArray(String value, final String split) {
        if (StringUtils.isBlank(value))
            return ArrayUtils.EMPTY_INT_ARRAY;
        value = StringUtils.remove(value, ' ');
        final String[] array = value.split(split);
        final int length = array.length;
        final int[] newArray = new int[length];
        for (int index = 0; index < length; index++) {
            if (StringUtils.isEmpty(array[index]))
                continue;
            array[index] = removeFloat(array[index]);
            newArray[index] = Integer.parseInt(array[index]);
        }
        return newArray;
    }

    /**
     * 把字符串切割成long[]
     *
     * @param value 要切割的字符串，如"1,2,3"
     * @param split 分隔符
     * @return
     */
    public static long[] split2LongArray(String value, final String split) {
        if (StringUtils.isBlank(value))
            return ArrayUtils.EMPTY_LONG_ARRAY;
        value = StringUtils.remove(value, ' ');
        final String[] array = value.split(split);
        final int length = array.length;
        final long[] newArray = new long[length];
        for (int index = 0; index < length; index++) {
            if (StringUtils.isEmpty(array[index]))
                continue;
            array[index] = removeFloat(array[index]);
            newArray[index] = Long.parseLong(array[index]);
        }
        return newArray;
    }

    /**
     * 把字符串切割成float[]
     *
     * @param value 要切割的字符串，如"1.0,2.0,3.0"
     * @param split 分隔符
     * @return
     */
    public static float[] split2FloatArray(String value, final String split) {
        if (StringUtils.isBlank(value))
            return ArrayUtils.EMPTY_FLOAT_ARRAY;
        value = StringUtils.remove(value, ' ');
        final String[] array = value.split(split);
        final int length = array.length;
        final float[] newArray = new float[length];
        for (int index = 0; index < length; index++) {
            if (StringUtils.isEmpty(array[index]))
                continue;
            newArray[index] = Float.parseFloat(array[index]);
        }
        return newArray;
    }

    /**
     * 把字符串切割成String[]
     *
     * @param value 要切割的字符串，如"1,2,3"
     * @param split 分隔符
     * @return
     */
    public static String[] split2StringArray(String value, final String split) {
        if (StringUtils.isBlank(value))
            return ArrayUtils.EMPTY_STRING_ARRAY;
        final String[] array = value.split(split);
        final int length = array.length;
        final String[] newArray = new String[length];
        for (int index = 0; index < length; index++) {
            if (StringUtils.isEmpty(array[index]))
                continue;
            newArray[index] = array[index];
        }
        return newArray;
    }

    /**
     * 把字符串切割成List<Integer>
     *
     * @param value 要切割的字符串，如"1,2,3"
     * @param split 分隔符
     * @return
     */
    public static List<Integer> split2IntList(String value, final String split) {
        return split2IntList(value, split, false);
    }

    /**
     * 把字符串切割成List<Integer>
     *
     * @param value     要切割的字符串，如"1,2,3"
     * @param split     分隔符
     * @param immutable 集合是否不可变
     * @return
     */
    public static List<Integer> split2IntList(String value, final String split, final boolean immutable) {
        if (StringUtils.isBlank(value))
            return Collections.emptyList();
        value = StringUtils.remove(value, ' ');
        final String[] array = value.split(split);
        final int length = array.length;
        final List<Integer> list = Lists.newArrayListWithExpectedSize(length);
        for (int index = 0; index < length; index++) {
            if (StringUtils.isEmpty(array[index]))
                continue;
            array[index] = removeFloat(array[index]);
            list.add(Integer.parseInt(array[index]));
        }
        return immutable ? ImmutableList.copyOf(list) : list;
    }

    /**
     * 把字符串切割成List<Long>
     *
     * @param value 要切割的字符串，如"1,2,3"
     * @param split 分隔符
     * @return
     */
    public static List<Long> split2LongList(String value, final String split) {
        return split2LongList(value, split, false);
    }

    /**
     * 把字符串切割成List<Long>
     *
     * @param value     要切割的字符串，如"1,2,3"
     * @param split     分隔符
     * @param immutable 集合是否不可变
     * @return
     */
    public static List<Long> split2LongList(String value, final String split, final boolean immutable) {
        if (StringUtils.isBlank(value))
            return Collections.emptyList();
        value = StringUtils.remove(value, ' ');
        final String[] array = value.split(split);
        final int length = array.length;
        final List<Long> list = Lists.newArrayListWithExpectedSize(length);
        for (int index = 0; index < length; index++) {
            if (StringUtils.isEmpty(array[index]))
                continue;
            array[index] = removeFloat(array[index]);
            list.add(Long.parseLong(array[index]));
        }
        return immutable ? ImmutableList.copyOf(list) : list;
    }

    /**
     * 把字符串切割成List<Float>
     *
     * @param value 要切割的字符串，如"1.0,2.0,3.0"
     * @param split 分隔符
     * @return
     */
    public static List<Float> split2FloatList(String value, final String split) {
        return split2FloatList(value, split, false);
    }

    /**
     * 把字符串切割成List<Float>
     *
     * @param value     要切割的字符串，如"1.0,2.0,3.0"
     * @param split     分隔符
     * @param immutable 集合是否不可变
     * @return
     */
    public static List<Float> split2FloatList(String value, final String split, final boolean immutable) {
        if (StringUtils.isBlank(value))
            return Collections.emptyList();
        value = StringUtils.remove(value, ' ');
        final String[] array = value.split(split);
        final int length = array.length;
        final List<Float> list = Lists.newArrayListWithExpectedSize(length);
        for (int index = 0; index < length; index++) {
            if (StringUtils.isEmpty(array[index]))
                continue;
            list.add(Float.parseFloat(array[index]));
        }
        return immutable ? ImmutableList.copyOf(list) : list;
    }

    /**
     * 把字符串切割成List<String>
     *
     * @param value 要切割的字符串，如"1,2,3"
     * @param split 分隔符
     * @return
     */
    public static List<String> split2StringList(String value, final String split) {
        return split2StringList(value, split, false);
    }

    /**
     * 把字符串切割成List<String>
     *
     * @param value     要切割的字符串，如"1,2,3"
     * @param split     分隔符
     * @param immutable 集合是否不可变
     * @return
     */
    public static List<String> split2StringList(String value, final String split, final boolean immutable) {
        if (StringUtils.isBlank(value))
            return Collections.emptyList();
        value = StringUtils.remove(value, ' ');
        final String[] array = value.split(split);
        final int length = array.length;
        final List<String> list = Lists.newArrayListWithExpectedSize(length);
        for (int index = 0; index < length; index++) {
            if (StringUtils.isEmpty(array[index]))
                continue;
            list.add(array[index]);
        }
        return immutable ? ImmutableList.copyOf(list) : list;
    }

    /**
     * 把字符串切割成Set<Integer>
     *
     * @param value 要切割的字符串，如"1,2,3"
     * @param split 分隔符
     * @return
     */
    public static Set<Integer> split2IntSet(String value, final String split) {
        return split2IntSet(value, split, false);
    }

    /**
     * 把字符串切割成Set<Integer>
     *
     * @param value     要切割的字符串，如"1,2,3"
     * @param split     分隔符
     * @param immutable 集合是否不可变
     * @return
     */
    public static Set<Integer> split2IntSet(String value, final String split, final boolean immutable) {
        if (StringUtils.isBlank(value))
            return Collections.emptySet();
        value = StringUtils.remove(value, ' ');
        final String[] array = value.split(split);
        final int length = array.length;
        final Set<Integer> set = Sets.newHashSetWithExpectedSize(length);
        for (int index = 0; index < length; index++) {
            if (StringUtils.isEmpty(array[index]))
                continue;
            array[index] = removeFloat(array[index]);
            set.add(Integer.parseInt(array[index]));
        }
        return immutable ? ImmutableSet.copyOf(set) : set;
    }


    /**
     * 把字符串切割成Set<Long>
     *
     * @param value 要切割的字符串，如"1,2,3"
     * @param split 分隔符
     * @return
     */
    public static Set<Long> split2LongSet(String value, final String split) {
        return split2LongSet(value, split, false);
    }

    /**
     * 把字符串切割成Set<Long>
     *
     * @param value     要切割的字符串，如"1,2,3"
     * @param split     分隔符
     * @param immutable 集合是否不可变
     * @return
     */
    public static Set<Long> split2LongSet(String value, final String split, final boolean immutable) {
        if (StringUtils.isBlank(value))
            return Collections.emptySet();
        value = StringUtils.remove(value, ' ');
        final String[] array = value.split(split);
        final int length = array.length;
        final Set<Long> set = Sets.newHashSetWithExpectedSize(length);
        for (int index = 0; index < length; index++) {
            if (StringUtils.isEmpty(array[index]))
                continue;
            array[index] = removeFloat(array[index]);
            set.add(Long.parseLong(array[index]));
        }
        return immutable ? ImmutableSet.copyOf(set) : set;
    }


    /**
     * 把字符串切割成Set<Float>
     *
     * @param value 要切割的字符串，如"1.0,2.0,3.0"
     * @param split 分隔符
     * @return
     */
    public static Set<Float> split2FloatSet(String value, final String split) {
        return split2FloatSet(value, split, false);
    }

    /**
     * 把字符串切割成Set<Float>
     *
     * @param value     要切割的字符串，如"1.0,2.0,3.0"
     * @param split     分隔符
     * @param immutable 集合是否不可变
     * @return
     */
    public static Set<Float> split2FloatSet(String value, final String split, final boolean immutable) {
        if (StringUtils.isBlank(value))
            return Collections.emptySet();
        value = StringUtils.remove(value, ' ');
        final String[] array = value.split(split);
        final int length = array.length;
        final Set<Float> set = Sets.newHashSetWithExpectedSize(length);
        for (int index = 0; index < length; index++) {
            if (StringUtils.isEmpty(array[index]))
                continue;
            set.add(Float.parseFloat(array[index]));
        }
        return immutable ? ImmutableSet.copyOf(set) : set;
    }


    /**
     * 把字符串切割成Set<String>
     *
     * @param value 要切割的字符串，如"1,2,3"
     * @param split 分隔符
     * @return
     */
    public static Set<String> split2StringSet(String value, String split) {
        return split2StringSet(value, split, false);
    }

    /**
     * 把字符串切割成Set<String>
     *
     * @param value     要切割的字符串，如"1,2,3"
     * @param split     分隔符
     * @param immutable 集合是否不可变
     * @return
     */
    public static Set<String> split2StringSet(String value, final String split, final boolean immutable) {
        if (StringUtils.isBlank(value))
            return Collections.emptySet();
        value = StringUtils.remove(value, ' ');
        final String[] array = value.split(split);
        final int length = array.length;
        final Set<String> set = Sets.newHashSetWithExpectedSize(length);
        for (int index = 0; index < length; index++) {
            if (StringUtils.isEmpty(array[index]))
                continue;
            set.add(array[index]);
        }
        return immutable ? ImmutableSet.copyOf(set) : set;
    }


    /**
     * 把字符串切割成Map<Integer, Integer>
     *
     * @param value  要切割的字符串，如"1=1,2=2,3=3"
     * @param split1 第一层分隔符
     * @param split2 第二层分隔符
     * @return
     */
    public static Map<Integer, Integer> split2IIMap(String value, final String split1, final String split2) {
        return split2IIMap(value, split1, split2, false);
    }

    /**
     * 把字符串切割成Map<Integer, Integer>
     *
     * @param value     要切割的字符串，如"1=1,2=2,3=3"
     * @param split1    第一层分隔符
     * @param split2    第二层分隔符
     * @param immutable 集合是否不可变
     * @return
     */
    public static Map<Integer, Integer> split2IIMap(String value, final String split1, final String split2, final boolean immutable) {
        if (StringUtils.isBlank(value))
            return Collections.emptyMap();
        value = StringUtils.remove(value, ' ');
        final String[] firstArray = value.split(split1);
        final int length = firstArray.length;
        final Map<Integer, Integer> map = Maps.newLinkedHashMapWithExpectedSize(length);
        for (int index = 0; index < length; index++) {
            if (StringUtils.isEmpty(firstArray[index]))
                continue;
            firstArray[index] = removeFloat(firstArray[index]);
            final String[] secondArray = firstArray[index].split(split2);
            map.put(Integer.parseInt(secondArray[0]), Integer.parseInt(secondArray[1]));
        }
        return immutable ? ImmutableMap.copyOf(map) : map;
    }

    /**
     * 把字符串切割成Map<Integer, Long>
     *
     * @param value  要切割的字符串，如"1=1,2=2,3=3"
     * @param split1 第一层分隔符
     * @param split2 第二层分隔符
     * @return
     */
    public static Map<Integer, Long> split2ILMap(String value, final String split1, final String split2) {
        return split2ILMap(value, split1, split2, false);
    }

    /**
     * 把字符串切割成Map<Integer, Long>
     *
     * @param value     要切割的字符串，如"1=1,2=2,3=3"
     * @param split1    第一层分隔符
     * @param split2    第二层分隔符
     * @param immutable 集合是否不可变
     * @return
     */
    public static Map<Integer, Long> split2ILMap(String value, final String split1, final String split2, final boolean immutable) {
        if (StringUtils.isBlank(value))
            return Collections.emptyMap();
        value = StringUtils.remove(value, ' ');
        final String[] firstArray = value.split(split1);
        final int length = firstArray.length;
        final Map<Integer, Long> map = Maps.newLinkedHashMapWithExpectedSize(length);
        for (int index = 0; index < length; index++) {
            if (StringUtils.isEmpty(firstArray[index]))
                continue;
            firstArray[index] = removeFloat(firstArray[index]);
            final String[] secondArray = firstArray[index].split(split2);
            map.put(Integer.parseInt(secondArray[0]), Long.parseLong(secondArray[1]));
        }
        return immutable ? ImmutableMap.copyOf(map) : map;
    }

    /**
     * 把字符串切割成Map<Integer, Float>
     *
     * @param value  要切割的字符串，如"1=1.0,2=2.0,3=3.0"
     * @param split1 第一层分隔符
     * @param split2 第二层分隔符
     * @return
     */
    public static Map<Integer, Float> split2IFMap(String value, final String split1, final String split2) {
        return split2IFMap(value, split1, split2, false);
    }

    /**
     * 把字符串切割成Map<Integer, Float>
     *
     * @param value     要切割的字符串，如"1=1.0,2=2.0,3=3.0"
     * @param split1    第一层分隔符
     * @param split2    第二层分隔符
     * @param immutable 集合是否不可变
     * @return
     */
    public static Map<Integer, Float> split2IFMap(String value, final String split1, final String split2, final boolean immutable) {
        if (StringUtils.isBlank(value))
            return Collections.emptyMap();
        value = StringUtils.remove(value, ' ');
        final String[] firstArray = value.split(split1);
        final int length = firstArray.length;
        final Map<Integer, Float> map = Maps.newLinkedHashMapWithExpectedSize(length);
        for (int index = 0; index < length; index++) {
            if (StringUtils.isEmpty(firstArray[index]))
                continue;
            String[] secondArray = firstArray[index].split(split2);
            map.put(Integer.parseInt(secondArray[0]), Float.parseFloat(secondArray[1]));
        }
        return immutable ? ImmutableMap.copyOf(map) : map;
    }

    /**
     * 把字符串切割成Map<Integer, String>
     *
     * @param value  要切割的字符串，如"1=1,2=2,3=3"
     * @param split1 第一层分隔符
     * @param split2 第二层分隔符
     * @return
     */
    public static Map<Integer, String> split2ISMap(String value, final String split1, final String split2) {
        return split2ISMap(value, split1, split2);
    }

    /**
     * 把字符串切割成Map<Integer, String>
     *
     * @param value     要切割的字符串，如"1=1,2=2,3=3"
     * @param split1    第一层分隔符
     * @param split2    第二层分隔符
     * @param immutable 集合是否不可变
     * @return
     */
    public static Map<Integer, String> split2ISMap(String value, final String split1, final String split2, final boolean immutable) {
        if (StringUtils.isBlank(value))
            return Collections.emptyMap();
        value = StringUtils.remove(value, ' ');
        final String[] firstArray = value.split(split1);
        final int length = firstArray.length;
        final Map<Integer, String> map = Maps.newLinkedHashMapWithExpectedSize(length);
        for (int index = 0; index < length; index++) {
            if (StringUtils.isEmpty(firstArray[index]))
                continue;
            final String[] secondArray = firstArray[index].split(split2);
            map.put(Integer.parseInt(secondArray[0]), secondArray[1]);
        }
        return immutable ? ImmutableMap.copyOf(map) : map;
    }

    /**
     * 把字符串切割成Map<Long, Integer>
     *
     * @param value  要切割的字符串，如"1=1,2=2,3=3"
     * @param split1 第一层分隔符
     * @param split2 第二层分隔符
     * @return
     */
    public static Map<Long, Integer> split2LIMap(String value, final String split1, final String split2) {
        return split2LIMap(value, split1, split2, false);
    }

    /**
     * 把字符串切割成Map<Long, Integer>
     *
     * @param value     要切割的字符串，如"1=1,2=2,3=3"
     * @param split1    第一层分隔符
     * @param split2    第二层分隔符
     * @param immutable 集合是否不可变
     * @return
     */
    public static Map<Long, Integer> split2LIMap(String value, final String split1, final String split2, final boolean immutable) {
        if (StringUtils.isBlank(value))
            return Collections.emptyMap();
        value = StringUtils.remove(value, ' ');
        final String[] firstArray = value.split(split1);
        final int length = firstArray.length;
        final Map<Long, Integer> map = Maps.newLinkedHashMapWithExpectedSize(length);
        for (int index = 0; index < length; index++) {
            if (StringUtils.isEmpty(firstArray[index]))
                continue;
            firstArray[index] = removeFloat(firstArray[index]);
            final String[] secondArray = firstArray[index].split(split2);
            map.put(Long.parseLong(secondArray[0]), Integer.parseInt(secondArray[1]));
        }
        return immutable ? ImmutableMap.copyOf(map) : map;
    }

    /**
     * 把字符串切割成Map<Long, Long>
     *
     * @param value  要切割的字符串，如"1=1,2=2,3=3"
     * @param split1 第一层分隔符
     * @param split2 第二层分隔符
     * @return
     */
    public static Map<Long, Long> split2LLMap(String value, final String split1, final String split2) {
        return split2LLMap(value, split1, split2, false);
    }

    /**
     * 把字符串切割成Map<Long, Long>
     *
     * @param value     要切割的字符串，如"1=1,2=2,3=3"
     * @param split1    第一层分隔符
     * @param split2    第二层分隔符
     * @param immutable 集合是否不可变
     * @return
     */
    public static Map<Long, Long> split2LLMap(String value, final String split1, final String split2, final boolean immutable) {
        if (StringUtils.isBlank(value))
            return Collections.emptyMap();
        value = StringUtils.remove(value, ' ');
        final String[] firstArray = value.split(split1);
        final int length = firstArray.length;
        final Map<Long, Long> map = Maps.newLinkedHashMapWithExpectedSize(length);
        for (int index = 0; index < length; index++) {
            if (StringUtils.isEmpty(firstArray[index]))
                continue;
            firstArray[index] = removeFloat(firstArray[index]);
            final String[] secondArray = firstArray[index].split(split2);
            map.put(Long.parseLong(secondArray[0]), Long.parseLong(secondArray[1]));
        }
        return immutable ? ImmutableMap.copyOf(map) : map;
    }

    /**
     * 把字符串切割成Map<String, Integer>
     *
     * @param value  要切割的字符串，如"1=1,2=2,3=3"
     * @param split1 第一层分隔符
     * @param split2 第二层分隔符
     * @return
     */
    public static Map<String, Integer> split2SIMap(String value, final String split1, final String split2) {
        return split2SIMap(value, split1, split2);
    }

    /**
     * 把字符串切割成Map<String, Integer>
     *
     * @param value     要切割的字符串，如"1=1,2=2,3=3"
     * @param split1    第一层分隔符
     * @param split2    第二层分隔符
     * @param immutable 集合是否不可变
     * @return
     */
    public static Map<String, Integer> split2SIMap(String value, final String split1, final String split2, final boolean immutable) {
        if (StringUtils.isBlank(value))
            return Collections.emptyMap();
        value = StringUtils.remove(value, ' ');
        final String[] firstArray = value.split(split1);
        final int length = firstArray.length;
        final Map<String, Integer> map = Maps.newLinkedHashMapWithExpectedSize(length);
        for (int index = 0; index < length; index++) {
            if (StringUtils.isEmpty(firstArray[index]))
                continue;
            String[] secondArray = firstArray[index].split(split2);
            secondArray[1] = removeFloat(secondArray[1]);
            map.put(secondArray[0], Integer.parseInt(secondArray[1]));
        }
        return immutable ? ImmutableMap.copyOf(map) : map;
    }


    /**
     * 把字符串切割成Map<String, Long>
     *
     * @param value  要切割的字符串，如"1=1,2=2,3=3"
     * @param split1 第一层分隔符
     * @param split2 第二层分隔符
     * @return
     */
    public static Map<String, Long> split2SLMap(String value, final String split1, final String split2) {
        return split2SLMap(value, split1, split2);
    }

    /**
     * 把字符串切割成Map<String, Integer>
     *
     * @param value     要切割的字符串，如"1=1,2=2,3=3"
     * @param split1    第一层分隔符
     * @param split2    第二层分隔符
     * @param immutable 集合是否不可变
     * @return
     */
    public static Map<String, Long> split2SLMap(String value, final String split1, final String split2, final boolean immutable) {
        if (StringUtils.isBlank(value))
            return Collections.emptyMap();
        value = StringUtils.remove(value, ' ');
        final String[] firstArray = value.split(split1);
        final int length = firstArray.length;
        final Map<String, Long> map = Maps.newLinkedHashMapWithExpectedSize(length);
        for (int index = 0; index < length; index++) {
            if (StringUtils.isEmpty(firstArray[index]))
                continue;
            String[] secondArray = firstArray[index].split(split2);
            secondArray[1] = removeFloat(secondArray[1]);
            map.put(secondArray[0], Long.parseLong(secondArray[1]));
        }
        return immutable ? ImmutableMap.copyOf(map) : map;
    }

    /**
     * 把字符串切割成Map<String, Float>
     *
     * @param value  要切割的字符串，如"1=1.0,2=2.0,3=3.0"
     * @param split1 第一层分隔符
     * @param split2 第二层分隔符
     * @return
     */
    public static Map<String, Float> split2SFMap(String value, final String split1, final String split2) {
        return split2SFMap(value, split1, split2);
    }

    /**
     * 把字符串切割成Map<String, Float>
     *
     * @param value     要切割的字符串，如"1=1.0,2=2.0,3=3.0"
     * @param split1    第一层分隔符
     * @param split2    第二层分隔符
     * @param immutable 集合是否不可变
     * @return
     */
    public static Map<String, Float> split2SFMap(String value, final String split1, final String split2, final boolean immutable) {
        if (StringUtils.isBlank(value))
            return Collections.emptyMap();
        value = StringUtils.remove(value, ' ');
        String[] firstArray = value.split(split1);
        int length = firstArray.length;
        Map<String, Float> map = Maps.newLinkedHashMapWithExpectedSize(length);
        for (int index = 0; index < length; index++) {
            if (StringUtils.isEmpty(firstArray[index]))
                continue;
            String[] secondArray = firstArray[index].split(split2);
            map.put(secondArray[0], Float.parseFloat(secondArray[1]));
        }
        return immutable ? ImmutableMap.copyOf(map) : map;
    }


    /**
     * 把字符串切割成Map<String, String>
     *
     * @param value  要切割的字符串，如"1=1,2=2,3=3"
     * @param split1 第一层分隔符
     * @param split2 第二层分隔符
     * @return
     */
    public static Map<String, String> split2SSMap(String value, final String split1, final String split2) {
        return split2SSMap(value, split1, split2, false);
    }

    /**
     * 把字符串切割成Map<String, String>
     *
     * @param value     要切割的字符串，如"1=1,2=2,3=3"
     * @param split1    第一层分隔符
     * @param split2    第二层分隔符
     * @param immutable 集合是否不可变
     * @return
     */
    public static Map<String, String> split2SSMap(String value, final String split1, final String split2, final boolean immutable) {
        if (StringUtils.isBlank(value))
            return Collections.emptyMap();
        value = StringUtils.remove(value, ' ');
        String[] firstArray = value.split(split1);
        int length = firstArray.length;
        Map<String, String> map = Maps.newLinkedHashMapWithExpectedSize(length);
        for (int index = 0; index < length; index++) {
            if (StringUtils.isEmpty(firstArray[index]))
                continue;
            String[] secondArray = firstArray[index].split(split2);
            if (secondArray.length == 1) {
                map.put(secondArray[0], null);
            } else {
                map.put(secondArray[0], secondArray[1]);
            }
        }
        return immutable ? ImmutableMap.copyOf(map) : map;
    }

    /**
     * 把字符串切割成Map<String, Integer[]>
     *
     * @param value  要切割的字符串，如"1=1,2=2,3=3"
     * @param split1 第一层分隔符
     * @param split2 第二层分隔符
     * @return
     */
    public static Map<String, Integer[]> split2SIArrayMap(String value, final String split1, final String split2) {
        return split2SIArrayMap(value, split1, split2, false);
    }

    /**
     * 把字符串切割成Map<String, Integer[]>
     *
     * @param value     要切割的字符串，如"1=1,2=2,3=3"
     * @param split1    第一层分隔符
     * @param split2    第二层分隔符
     * @param immutable 集合是否不可变
     * @return
     */
    public static Map<String, Integer[]> split2SIArrayMap(String value, final String split1, final String split2, final boolean immutable) {
        if (StringUtils.isBlank(value))
            return Collections.emptyMap();
        value = StringUtils.remove(value, ' ');
        final String[] firstArray = value.split(split1);
        final int length = firstArray.length;
        final Map<String, Integer[]> map = Maps.newLinkedHashMapWithExpectedSize(length);
        for (int i = 0; i < length; i++) {
            if (StringUtils.isEmpty(firstArray[i]))
                continue;
            final String[] secondArray = firstArray[i].split(split2);
            final int secondLength = secondArray.length;
            final String property = secondArray[0];
            Integer[] values = map.get(property);
            if (values == null) {
                values = new Integer[secondLength - 1];
                map.put(property, values);
            }
            for (int j = 1; j < secondLength; j++)
                values[j] = Integer.valueOf(secondArray[j]);
        }
        return immutable ? ImmutableMap.copyOf(map) : map;
    }

    /**
     * 把字符串切割成int[][]
     *
     * @param value  要切割的字符串，如"1=1,2=2,3=3"
     * @param split1 第一层分隔符
     * @param split2 第二层分隔符
     * @return
     */
    public static int[][] split2IntArray(String value, final String split1, final String split2) {
        if (StringUtils.isBlank(value))
            return new int[0][0];
        value = StringUtils.remove(value, ' ');
        final String[] firstArray = value.split(split1);
        final int length = firstArray.length;
        final int[][] newArray = new int[length][];
        for (int i = 0; i < length; i++) {
            if (StringUtils.isEmpty(firstArray[i]))
                continue;
            firstArray[i] = removeFloat(firstArray[i]);
            final String[] secondArray = firstArray[i].split(split2);
            final int secondLength = secondArray.length;
            final int[] secondNewArray = new int[secondLength];
            for (int j = 0; j < secondLength; j++)
                secondNewArray[j] = Integer.parseInt(secondArray[j]);
            newArray[i] = secondNewArray;
        }
        return newArray;
    }

    /**
     * 把字符串切割成long[][]
     *
     * @param value  要切割的字符串，如"1=1,2=2,3=3"
     * @param split1 第一层分隔符
     * @param split2 第二层分隔符
     * @return
     */
    public static long[][] split2LongArray(String value, final String split1, final String split2) {
        if (StringUtils.isBlank(value))
            return new long[0][0];
        value = StringUtils.remove(value, ' ');
        final String[] firstArray = value.split(split1);
        final int length = firstArray.length;
        final long[][] newArray = new long[length][];
        for (int i = 0; i < length; i++) {
            if (StringUtils.isEmpty(firstArray[i]))
                continue;
            firstArray[i] = removeFloat(firstArray[i]);
            final String[] secondArray = firstArray[i].split(split2);
            final int secondLength = secondArray.length;
            long[] secondNewArray = new long[secondLength];
            for (int j = 0; j < secondLength; j++)
                secondNewArray[j] = Long.parseLong(secondArray[j]);
            newArray[i] = secondNewArray;
        }
        return newArray;
    }

    /**
     * 把字符串切割成float[][]
     *
     * @param value  要切割的字符串，如"1.0=1.0,2.0=2.0,3.0=3.0"
     * @param split1 第一层分隔符
     * @param split2 第二层分隔符
     * @return
     */
    public static float[][] split2FloatArray(String value, final String split1, final String split2) {
        if (StringUtils.isBlank(value))
            return new float[0][0];
        value = StringUtils.remove(value, ' ');
        final String[] firstArray = value.split(split1);
        final int length = firstArray.length;
        final float[][] newArray = new float[length][];
        for (int i = 0; i < length; i++) {
            if (StringUtils.isEmpty(firstArray[i]))
                continue;
            final String[] secondArray = firstArray[i].split(split2);
            final int secondLength = secondArray.length;
            final float[] secondNewArray = new float[secondLength];
            for (int j = 0; j < secondLength; j++)
                secondNewArray[j] = Float.parseFloat(secondArray[j]);
            newArray[i] = secondNewArray;
        }
        return newArray;
    }

    /**
     * 把字符串切割成String[][]
     *
     * @param value  要切割的字符串，如"1=1,2=2,3=3"
     * @param split1 第一层分隔符
     * @param split2 第二层分隔符
     * @return
     */
    public static String[][] split2StringArray(String value, final String split1, final String split2) {
        if (StringUtils.isBlank(value))
            return new String[0][0];
        value = StringUtils.remove(value, ' ');
        final String[] firstArray = value.split(split1);
        final int length = firstArray.length;
        final String[][] newArray = new String[length][];
        for (int index = 0; index < length; index++) {
            if (StringUtils.isEmpty(firstArray[index]))
                continue;
            final String[] secondArray = firstArray[index].split(split2);
            newArray[index] = secondArray;
        }
        return newArray;
    }

    /**
     * 把Collection组合成字符串
     *
     * @param collection 要组合的Collection
     * @param split      分隔符
     * @return
     */
    public static String collectionJoin(final Collection<?> collection, final String split) {
        if (CollectionUtils.isEmpty(collection))
            return null;
        final StringBuilder builder = new StringBuilder();
        int index = 0;
        for (Object obj : collection) {
            if (index > 0)
                builder.append(split);
            builder.append(obj.toString());
            index++;
        }
        return builder.toString();
    }

    /**
     * 把Map组合成字符串
     *
     * @param map    要组合的Map
     * @param split1 第一层分隔符
     * @param split2 第二层分隔符
     * @return
     */
    public static String mapJoin(Map<?, ?> map, final String split1, final String split2) {
        if (MapUtils.isEmpty(map))
            return null;
        final StringBuilder builder = new StringBuilder();
        int index = 0;
        for (Map.Entry<?, ?> entry : map.entrySet()) {
            if (index > 0)
                builder.append(split1);
            builder.append(entry.getKey().toString())
                    .append(split2)
                    .append(entry.getValue().toString());
            index++;
        }
        return builder.toString();
    }

    /**
     * 把Object...组合成字符串
     *
     * @param split 分隔符
     * @param array 要组合的Object...
     * @return
     */
    public static String arrayJoin(final String split, final Object... array) {
        if (ArrayUtils.isEmpty(array))
            return null;
        final StringBuilder builder = new StringBuilder();
        for (int index = 0, length = array.length; index < length; index++) {
            if (index > 0)
                builder.append(split);
            builder.append(array[index]);
        }
        return builder.toString();
    }
}
